package com.zhaoxi.project.cms.type.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.zhaoxi.framework.aspectj.lang.annotation.Log;
import com.zhaoxi.framework.aspectj.lang.enums.BusinessType;
import com.zhaoxi.project.cms.type.domain.CmsType;
import com.zhaoxi.project.cms.type.service.impl.CmsTypeServiceImpl;
import com.zhaoxi.framework.web.controller.BaseController;
import com.zhaoxi.framework.web.domain.AjaxResult;
import com.zhaoxi.common.utils.poi.ExcelUtil;
import com.zhaoxi.framework.web.page.TableDataInfo;

/**
 * 分类信息Controller
 *
 * @author zhaoxi
 * @date 2023-07-27
 */
@RestController
@RequestMapping("/cms/type")
public class CmsTypeController extends BaseController
{
    @Autowired
    private CmsTypeServiceImpl cmsTypeService;

    /**
     * 查询分类信息列表
     */
    @PreAuthorize("@ss.hasPermi('cms:type:list')")
    @GetMapping("/list")
    public TableDataInfo list(CmsType cmsType)
    {
        startPage();
        List<CmsType> list = cmsTypeService.selectCmsTypeList(cmsType);
        return getDataTable(list);
    }

    /**
     * 导出分类信息列表
     */
    @PreAuthorize("@ss.hasPermi('cms:type:export')")
    @Log(title = "分类信息", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, CmsType cmsType)
    {
        List<CmsType> list = cmsTypeService.selectCmsTypeList(cmsType);
        ExcelUtil<CmsType> util = new ExcelUtil<CmsType>(CmsType.class);
        util.exportExcel(response, list, "分类信息数据");
    }

    /**
     * 获取分类信息详细信息
     */
    @PreAuthorize("@ss.hasPermi('cms:type:query')")
    @GetMapping(value = "/{typeId}")
    public AjaxResult getInfo(@PathVariable("typeId") Long typeId)
    {
        return success(cmsTypeService.selectCmsTypeByTypeId(typeId));
    }

    /**
     * 新增分类信息
     */
    @PreAuthorize("@ss.hasPermi('cms:type:add')")
    @Log(title = "分类信息", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody CmsType cmsType)
    {
        return toAjax(cmsTypeService.insertCmsType(cmsType));
    }

    /**
     * 修改分类信息
     */
    @PreAuthorize("@ss.hasPermi('cms:type:edit')")
    @Log(title = "分类信息", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody CmsType cmsType)
    {
        return toAjax(cmsTypeService.updateCmsType(cmsType));
    }

    /**
     * 删除分类信息
     */
    @PreAuthorize("@ss.hasPermi('cms:type:remove')")
    @Log(title = "分类信息", businessType = BusinessType.DELETE)
    @DeleteMapping("/{typeIds}")
    public AjaxResult remove(@PathVariable Long[] typeIds)
    {
        return toAjax(cmsTypeService.deleteCmsTypeByTypeIds(typeIds));
    }
}
